home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 827 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: thp@cs.ucr.edu (Tom Payne)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Referencing pointers after delete
  5. Date: 22 Mar 1996 14:09:50 PST
  6. Organization: University of California, Riverside
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4iushh$q3@galaxy.ucr.edu>
  9. References: <4is60i$ft6@galaxy.ucr.edu> <4isibn$el3@engnews1.Eng.Sun.COM>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 22 Mar 1996 18:46:09 GMT
  12. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  13. Content-Length: 1336
  14. X-Lines: 33
  15. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  16.     iQBVAwUBMVMlmUy4NqrwXLNJAQH6GwH9HG7gvBuNKKBS1DAGMUPglASlREbz5Y3V
  17.     XCS91lobaBNz4ZH4aQokLDtxMIc5I5Lsc7u32L/Gr/5vB2/QDLBe6w==
  18.     =2gge
  19. Originator: austern@isolde.mti.sgi.com
  20.  
  21. Steve Clamage (clamage@Eng.Sun.COM) wrote:
  22. : In article ft6@galaxy.ucr.edu, thp@cs.ucr.edu (Tom Payne) writes:
  23. : >....  It seems that to accomodate
  24. : >certain hardware-based validity checkers for pointers, the standard
  25. : >has precluded the possibility of portable software-based validity
  26. : >checking.  IMHO an unfortunate decision.
  27. : Even if the value of a pointer after its referent was deleted were 
  28. : required to be valid, it is still not possible to write a portable pointer
  29. : validity checker for C or C++. Example, assuming that it is always safe
  30. : to read the value of any pointer:
  31. :     void foo(int* p) {
  32. :         // is p valid?
  33. :     }
  34. : How are you going to determine portably whether p is valid in foo? 
  35.  
  36. By passing it to a checking routine, of course. ;-)  Given the curent
  37. standard, a call to such a routine can elicit undefined behavior in an
  38. otherwise portable program:
  39.  
  40.    void bar(int*& p) {
  41.       checkOut(p);  // p is passed by value to checkOut.
  42.       p = 0;
  43.    } 
  44.  
  45. I don't mean to imply that one can portably detect *all* invalid
  46. pointers, but with help from the compiler software-based solutions
  47. can give coverage that is as complete as those based on hardware.
  48. In either case, it is not particularly helpful that the behavior
  49. becomes undefined the moment an invalid value is detected.
  50.     
  51. Tom Payne (thp@cs.ucr.edu)
  52. ---
  53. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  54.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  55.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  56.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  57.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  58. ]
  59.